/**
 * @desc 考核管理
 * @author yd_zhaorongjun
 */
<template>
  <div class="gl_contentBox gl_heightFull">
    <div class="gl_searchBox">
      <el-row :gutter="20">
        <!-- 考核标题 -->
        <el-col :md="6" :lg="4">
          <p>{{ $t('search.name') }}</p>
          <el-input v-model="AssessmentQO.name" placeholder="考核标题" size="mini" clearable />
        </el-col>
        <el-col :md="6" :lg="4">
          <!-- 查询按钮 -->
          <el-button style="margin-top:27px" type="primary" size="mini" @click="refreshList">{{ $t('button.query') }}</el-button>
        </el-col>
      </el-row>
    </div>
    <template>
      <el-row :gutter="20" class="gl_my_15">
        <!-- 新增自定义项目 -->
        <el-col :md="6" :lg="4">
          <el-button type="primary" size="mini" @click="editOfAdd()">新增自定义项目</el-button>
        </el-col>
      </el-row>
      <el-table
        v-loading="loading"
        :data="tableData"
        stripe
        size="mini"
        style="width: 100%;"
      >
        <!-- 考核标题 -->
        <el-table-column
          prop="assessmentName"
          label="考核标题"
          width="240"
        />
        <!-- 考核项目 -->
        <el-table-column
          prop="assessmentItems"
          label="考核项目"
          min-width="260"
        />
        <!-- 考核时间 -->
        <el-table-column
          prop="assessmentTime"
          label="考核时间"
          align="center"
          width="160"
        />
        <!-- 操作 -->
        <el-table-column fixed="right" :label="$t('table.actions')" width="180">
          <template slot-scope="{row}">
            <!-- 考核按钮 -->
            <el-button v-if="!row.stateType" size="mini" type="text" @click="clickApproval(row)">
              考核
              <!-- {{ $t('table.examine') }} -->
            </el-button>
            <!-- 删除按钮 -->
            <el-button v-if="!row.stateType" size="mini" type="text" @click="clickDelete(row)">
              {{ $t('table.delete') }}
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-row class="gl_pt_20" style="text-align: center;">
        <el-pagination
          :current-page="AssessmentQO.pageIndex"
          :page-size="AssessmentQO.pageSize"
          :total="totalPage"
          layout="total,sizes,prev,pager,next,jumper"
          :page-sizes="[10, 20, 30, 40]"
          @size-change="sizeChange"
          @current-change="pageIndexChange"
        />
      </el-row>
    </template>

    <add-assessment ref="addAssessment" @insert="assessmentInsert" @update="assessmentUpdate" />
  </div>
</template>

<script>

import { AssessmentQO } from '@/lib/form/grade.js';
import { translateByCode } from '@/lib/getTransData';
import addAssessment from './addAssessment';
export default {
  name: 'Assessment',
  components: {
    addAssessment
  },
  data() {
    return {
      AssessmentQO: new AssessmentQO(),
      loading: false,
      totalPage: 0,
      tableData: [{
        assessmentName: '考核名称',
        assessmentTime: '2018-04-22 09:23:23',
        assessmentItems: '立定跳远'
      }, {
        assessmentName: '考核名称',
        assessmentTime: '2018-04-22 09:23:23',
        assessmentItems: '50米跑'
      }, {
        assessmentName: '考核名称',
        assessmentTime: '2018-04-22 09:23:23',
        assessmentItems: '立定跳远'
      }, {
        assessmentName: '考核名称',
        assessmentTime: '2018-04-22 09:23:23',
        assessmentItems: '立定跳远'
      }]
    };
  },
  computed: {
  },
  created() {
    this.refreshList();
  },
  methods: {
    // 刷新列表
    refreshList() {
      // TODO
    },
    // 重置搜索表单
    refreshSearchForm() {
      this.AssessmentQO = new AssessmentQO();
      this.freeDay = [];
    },
    // 添加或修改用户
    editOfAdd(row) {
      this.$refs.addAssessment.open(row);
    },
    // 删除按钮
    clickDelete(row) {
      // TODO
      // 您确定要删除 xxx 吗？ zh
      const _confirmStr = ` ${translateByCode('alert.wantDelete')} [ ${row.assessmentName} ] ${translateByCode('alert.ma')}`;
      this.$confirm(_confirmStr, translateByCode('alert.warning'), {
        confirmButtonText: translateByCode('alert.confirm'),
        cancelButtonText: translateByCode('alert.cancel'),
        type: 'warning'
      }).then(() => {
        this.$message({
          type: 'success',
          // 删除成功！
          message: translateByCode('alert.deleteSuccessfully')
        });
        this.refreshList();
      }).catch(() => {
      });
    },
    // 添加用户
    assessmentInsert(vo) {
      // TODO
      this.$message({
        // 添加成功！
        message: translateByCode('alert.addSuccessfully'),
        type: 'success'
      });
      this.$refs.addAssessment.close();
      this.refreshList();
    },
    // 修改用户
    assessmentUpdate(vo) {
      // TODO
      this.$message({
        // 修改成功！
        message: translateByCode('alert.editSuccessfully'),
        type: 'success'
      });
      this.$refs.addAssessment.close();
      this.refreshList();
    },
    sizeChange: function(pageSize) {
      this.AssessmentQO.pageSize = pageSize;
      this.refreshList();
    },
    pageIndexChange(pageIndex) {
      this.AssessmentQO.pageIndex = pageIndex;
      this.refreshList();
    }
  }
};
</script>

<style lang="scss" scoped>
</style>

